home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK2.toast / Development Kits (Disc 2) / ScriptX / Documentation / Code Examples from Docs / compguid / evntsdev / mausxing.sx < prev    next >
Encoding:
Text File  |  1996-05-21  |  2.6 KB  |  94 lines  |  [TEXT/ttxt]

  1. -- <<<-
  2.  
  3. -- mausXing.sx
  4. -- Mouse Crossing Event example
  5. -- by Howard Metzenberg
  6. -- Kaleida ScriptX forever
  7. -- from "Events and Input Devices" chapter of
  8. -- ScriptX Components Guide
  9.  
  10. -- This script demonstrates how to manage mouse-crossing events
  11.  
  12. -- Note that this script has changed since ScriptX 1.0
  13. -- Now you must force focus on a presenter other than TextEdit
  14.  
  15. module EventTest5 uses ScriptX end
  16. in module EventTest5
  17.  
  18. -- first create a window with default settings
  19. object myWindow (Window)
  20.     boundary:(new rect x2:600 y2:300)
  21.     settings x:20, y:40
  22. end
  23. show myWindow
  24.  
  25. global greenBrush := new Brush color:greenColor 
  26. global redBrush := new Brush color:redColor
  27.  
  28. class EnterPresenter(TwoDMultiPresenter)
  29. instance variables
  30.     mci -- an interest in mouse crossing events
  31. instance methods
  32.     method init self #rest args -> (    
  33.         apply nextMethod self args
  34.         -- create a mouse crossing event and set its properties
  35.         -- so that it can be used as an event interest
  36.         self.mci := new MouseCrossingEvent
  37.         self.mci.presenter := self
  38.         self.mci.authorData := self
  39.         self.mci.eventReceiver := colorme
  40.         -- register it as an event interest
  41.         addEventInterest(self.mci)
  42.     )
  43.     -- this method will receive mouse crossing events
  44.     method colorme self match myEvent -> (        
  45.         if (myEvent.crossingType = @enter) then (
  46.             self.fill := greenBrush -- green if you enter
  47.         ) else (
  48.             self.fill := redBrush -- red if you leave
  49.         )
  50.         print myEvent.crossingType
  51.         @accept -- accept the event, since asynchronous
  52.     )
  53. end
  54.  
  55. -- make some overlapping presenters that will receive
  56. -- mouse crossing events and add them to the window
  57. object shape1 (EnterPresenter) 
  58.     boundary:(new rect x2:240 y2:260), stroke:blackBrush
  59.     settings x:20, y:20
  60. end
  61. prepend myWindow shape1
  62. object shape2 (EnterPresenter) 
  63.     boundary:(new rect x2:340 y2:260), stroke:blackBrush
  64.     settings x:240, y:20
  65. end
  66. prepend myWindow shape2
  67. object shape3 (EnterPresenter) 
  68.     boundary:(new rect x2:180 y2:140), stroke:blackBrush
  69.     settings x:80, y:20
  70. end
  71. prepend myWindow shape3
  72. object shape4 (EnterPresenter) 
  73.     boundary:(new rect x2:180 y2:120), stroke:blackBrush
  74.     settings x:240, y:20
  75. end
  76. prepend myWindow shape4
  77. object shape5 (EnterPresenter) 
  78.     boundary:(new rect x2:200 y2:120), stroke:blackBrush
  79.     settings x:360, y:20
  80. end
  81. prepend myWindow shape5
  82.  
  83. -- make one more to put inside the last one
  84. object insideShape (EnterPresenter) 
  85.     boundary:(new rect x2:100 y2:100), stroke:blackBrush
  86.     settings x:100, y:50
  87. end
  88. -- put insideShape inside shape5 to show how 
  89. -- mouse crossing events works with the presentation hierarchy 
  90. -- note that it will be clipped by shape5
  91. prepend shape5 insideShape
  92.  
  93. -- >>>
  94.